﻿using MxWeiXinPF.Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MxWeiXinPF.Web.shop
{
    public partial class userbbsdetail : MxWeiXinPF.Web.UI.UserPage
    {
        private string action = MXEnums.ActionEnum.Add.ToString();
        public string carturl = "";
        public string ConsultView = "";
        private int id;
        public string indexurl = "";
        protected int shopid = 0x27;
        public string TitleName = "";
        protected int uid = 0;
        public string userinfourl = "";
        public string categoryurl = "";
        private void BindDate(int id)
        {
            string str = "../../upload/Default.jpg";
            DataSet bBSDS = new MxWeiXinPF.BLL.userbbs().GetBBSDS(id);
            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < bBSDS.Tables[0].Rows.Count; i++)
            {
                if (!(bBSDS.Tables[0].Rows[i]["imgurl"].ToString().Equals("") || (bBSDS.Tables[0].Rows[i]["imgurl"].ToString() == null)))
                {
                    str = bBSDS.Tables[0].Rows[i]["imgurl"].ToString();
                }
                else
                {
                    str = "../../upload/Default.jpg";
                }
                if (i == 0)
                {
                    this.TitleName = bBSDS.Tables[0].Rows[i]["title"].ToString();
                    builder.AppendFormat("<table width=\"0\" border=\"0\" cellspacing=\"0\" cellpadding=\0\" class=\"table1\">", new object[0]);
                    builder.AppendFormat("<tr><td style=\"width:70px;\"><div class=\"d_author\"><div class=\"yd_img\"><img src=\"" + str + "\" width=\"60\" height=\"60\" /></div>", new object[0]);
                    builder.AppendFormat("<a class=\"yd_name\">" + bBSDS.Tables[0].Rows[i]["username"].ToString() + "</a></div></td>", new object[0]);
                    builder.AppendFormat("<td style=\"width:100%;\"><div class=\"tip\"><p>" + bBSDS.Tables[0].Rows[i]["Remarks"].ToString() + "</p>", new object[0]);
                    builder.AppendFormat("<p class=\"hf_time\">" + bBSDS.Tables[0].Rows[i]["updatetime"].ToString() + "</p></div></td></tr></table>", new object[0]);
                }
                else if (bBSDS.Tables[0].Rows[i]["username"].ToString() == bBSDS.Tables[0].Rows[0]["username"].ToString())
                {
                    builder.AppendFormat("<table width=\"0\" border=\"0\" cellspacing=\"0\" cellpadding=\0\" class=\"table1\"><tr><td style=\"width:70px;\">", new object[0]);
                    builder.AppendFormat("<div class=\"d_author\"><div class=\"yd_img\"><img src=\"" + str + "\" width=\"60\" height=\"60\" /></div>", new object[0]);
                    builder.AppendFormat("<a class=\"yd_name\">" + bBSDS.Tables[0].Rows[i]["username"].ToString() + "</a></div></td>", new object[0]);
                    builder.AppendFormat("<td style=\"width:100%;\"><div class=\"tip\"><p>" + bBSDS.Tables[0].Rows[i]["Remarks"].ToString() + "</p>", new object[0]);
                    builder.AppendFormat("<p class=\"hf_time\">" + bBSDS.Tables[0].Rows[i]["updatetime"].ToString() + "</p></div></td></tr></table>", new object[0]);
                }
                else
                {
                    builder.AppendFormat("<table width=\"0\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table1\"><tr><td style=\"width:100%;\">", new object[0]);
                    builder.AppendFormat("<div class=\"tip2\">" + bBSDS.Tables[0].Rows[i]["Remarks"].ToString() + "<div class=\"hf_time\">" + bBSDS.Tables[0].Rows[i]["updatetime"].ToString() + "</div></div></td>", new object[0]);
                    builder.AppendFormat("<td style=\"width:70px;\"><div class=\"d_author\"><div class=\"yd_img\"><img src=\"" + str + "\" width=\"60\" height=\"60\" /></div>", new object[0]);
                    builder.AppendFormat("<a class=\"yd_name\" >" + bBSDS.Tables[0].Rows[i]["username"].ToString() + "</a></div></td></tr></table>", new object[0]);
                }
            }
            this.divContent.InnerHtml = builder.ToString();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.tbRemarks.Value))
            {
                this.Page.ClientScript.RegisterStartupScript(this.Page.ClientScript.GetType(), "myscripts", "<script>alert(\"留言内容不能为空 \");</script>");
            }
            else
            {
                MxWeiXinPF.BLL.userbbs userbbs = new MxWeiXinPF.BLL.userbbs();
                if (userbbs.AddDetail(this.id, this.tbRemarks.Value, this.uid, base.openid, this.shopid) > 0)
                {
                    this.BindDate(this.id);
                    this.tbRemarks.Value = "";
                    this.Page.ClientScript.RegisterStartupScript(this.Page.ClientScript.GetType(), "myscripts", "<script>alert(\"提交成功 \");</script>");
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                base.openid = MyCommFun.RequestOpenid();
                base.wid = MyCommFun.RequestInt("wid");
                this.id = MyCommFun.RequestInt("id");
                this.uid = MyCommFun.RequestInt("uid");
                this.shopid = MyCommFun.RequestInt("shopid");
                this.indexurl = string.Concat(new object[] { "index.aspx?wid=", base.wid, "&openid=", this.openid, "&shopid=", shopid });
                this.carturl = string.Concat(new object[] { "cart.aspx?wid=", base.wid, "&openid=", this.openid, "&shopid=", shopid });
                this.userinfourl = string.Concat(new object[] { "userinfo.aspx?wid=", base.wid, "&openid=", this.openid, "&shopid=", shopid });
                this.categoryurl = MyCommFun.urlAddOpenid("/shop/category.aspx?wid=" + base.wid + "&shopid=" + shopid, base.openid);
                if (!this.Page.IsPostBack)
                {
                    try
                    {
                        this.BindDate(this.id);
                    }
                    catch
                    {
                        this.Page.ClientScript.RegisterStartupScript(this.Page.ClientScript.GetType(), "myscripts", "<script>alert(\"参数错误 \");</script>");
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
    }
}